{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">信息管理</li>
            <li class=""><a href="{:url('admin/UsedTruck/add')}">添加信息</a></li>
        </ul>
        <div class="layui-tab-content">

            <form class="layui-form layui-form-pane" action="{:url('admin/UsedTruck/index')}" method="get">
                
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">车型</label>
                    <div class="layui-input-inline" style="width:160px;">
                            <select name="type" class="site">
                                <option value="0">车型</option>
                                {foreach name="used_list" item="vo"}
                                {if $vo.pid == 0 and $vo.cid == 1}
                                {foreach name='used_list' item='lo'}
                                {if $lo.pid[0] == $vo.id}
                                <option value="{$lo.id}">{$lo.name}</option>
                                {/if}
                                {/foreach}
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">品牌</label>
                    <div class="layui-input-inline" style="width:160px;">
                        <select name="brand" class="site">
                            <option value="0">品牌</option>
                            
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">车系</label>
                    <div class="layui-input-inline" style="width:160px;">
                        <select name="series" class="site">
                            <option value="0">车系</option>
                            
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">型号</label>
                    <div class="layui-input-inline" style="width:160px;">
                        <select name="version"> 
                            <option value="0">型号</option>                                
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="coding" value="{$coding}" placeholder="请输入编号" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" value="{$title}" placeholder="请输入标题关键词" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline"  style="margin-bottom: 5px;">
                    <button class="layui-btn">搜索</button>
                </div>
            </form>
            <hr>

            <form action="" method="post" class="ajax-form">
                <button type="button" class="layui-btn layui-btn-small ajax-action" data-action="{:url('admin/UsedTruck/toggle',['type'=>'audit'])}">审核</button>
                <button type="button" class="layui-btn layui-btn-warm layui-btn-small ajax-action" data-action="{:url('admin/UsedTruck/toggle',['type'=>'cancel_audit'])}">取消审核</button>
                <button type="button" class="layui-btn layui-btn-danger layui-btn-small ajax-action" data-action="{:url('admin/UsedTruck/delete')}">删除</button>
                <div class="layui-tab-item layui-show">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="width: 15px;"><input type="checkbox" class="check-all"></th>
                            <th style="width: 30px;">ID</th>
                            <th style="width: 30px;">用户</th>
                            <th>编号</th>
                            <th>标题</th>
                            <th>车型</th>
                            <th>品牌</th>
                            <th>车系</th>
                            <th>型号</th>
                            <th>价格</th>
                            <th>发布时间</th>
                            <th>查看(次)</th>
                            <th>审核</th>
                            <th>交易</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="usedtruck_list" item="vo"}
                        <tr>
                            <td><input type="checkbox" name="ids[]" value="{$vo.id}"></td>
                            <td>{$vo.id}</td>
                            <td>{$vo.user_id}</td>
                            <td>{$vo.coding}</td>
                            <td>{$vo.title}</td>
                            <td>{$classify_list[$vo['type']]}</td>
                            <td>{$classify_list[$vo['brand']]}</td>
                            <td>{$classify_list[$vo['series']]}</td>
                            <td>{$classify_list[$vo['version']]}</td>
                            <td>{$vo.price}</td>
                            <td>{$vo.create_time}</td>
                            <td>{$vo.reading}</td>
                            <td>
                            {if $vo.status==1}
                                    <i style="font-style: normal;color:#4caf50;">已审核</i>
                                {else /}
                                    <button type="button" class="layui-btn layui-btn-small ajax-action layui-btn-mini" data-action="{:url('admin/UsedTruck/toggle',['type'=>'audit','id'=>$vo['id']])}">审核</button>
                                {/if}
                            </td>
                            <td>
                            {if $vo.deal==1}
                                    <i style="font-style: normal;color:#4caf50;">已交易</i>
                                {else /}
                                    <a href="{:url('admin/UsedDeal/add',['truck_id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-mini">交易</a>
                                   <!-- <i style="font-style: normal;color:#e90d24;">未交易</i> -->
                                {/if}
                            </td>
                            <td>
                                <a href="{:url('admin/UsedTruck/reading',['id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-mini">查看</a>
                                <a href="{:url('admin/UsedTruck/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
                                <a href="{:url('admin/UsedTruck/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                    <!--分页-->
                    {$usedtruck_list->render()}
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
$(document).ready(function () {

    form.on('select',function(){
        $("select.site").next().find('dl').on('click','dd',function(){
            var jilu = '.layui-inline';
            var parent_id = $(this).attr('lay-value');
            var index = $(this).parents(jilu).index()+1;

            if(parent_id != 0){             
                $.ajax({
                    url:'/admin/used_classify2/jilm',
                    data:"id="+parent_id,
                    success:function(ell){
                        var i = 0;
                        xuan();

                        for(;i<ell.data.length;i++){
                            $(jilu).eq(index).find('select').append('<option value='+ell.data[i].id+'>'+ell.data[i].name+'</option>');
                            $(jilu).eq(index).find('dl').append('<dd lay-value='+ell.data[i].name+'>'+ell.data[i].name+'</dd>');
                        }
                        form.render('select');
                        
                    }
                });
            }else{
                xuan();
                form.render('select');
            }

            function xuan(){
                // console.log(index);
                if(index != 0){
                    for(var j=0;j<4;j++){
                        if(j > (index-1)){
                            // console.log('j:'+j);
                            $(jilu).eq(j).find('select').html('');
                            $(jilu).eq(j).find('dl').html('');
                            $(jilu).eq(j).find('select').append('<option value="0">全部</option>');
                            $(jilu).eq(j).find('dl').append('<dd lay-value="0">全部</dd>');
                            
                        }
                    }
                }
            }
            
        });
    });



});
</script>
{/block}